package com.easy.service.impl;

import com.easy.bean.Reservation;
import com.easy.mapper.ReservationDao;
import com.easy.service.ReservationService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReservationServiceimpl implements ReservationService {

    @Autowired
    ReservationDao reservationDao;

    @Override
    public Reservation add(Reservation reservation) {
        //新增数据
        reservationDao.add(reservation);
        //通过主键查询数据库中的数据
        Reservation result = reservationDao.one(reservation.getId());
        return result;
    }

    @Override
    public int del(Integer id) {
        return reservationDao.del(id);
    }

    @Override
    public Reservation edit(Reservation reservation) {
        reservationDao.edit(reservation);
        Reservation result = reservationDao.one(reservation.getId());
        return result;
    }

    @Override
    public List<Reservation> all(Reservation reservation) {
        return reservationDao.all(reservation);
    }

    @Override
    public Reservation one(Integer id) {
        return reservationDao.one(id);
    }

    @Override
    public void page(Page page, Reservation reservation) {
        int count = reservationDao.pageCount(reservation);
        Object data = reservationDao.page(page, reservation);
        page.setCount(count);
        page.setData(data);
    }

    @Override
    public void pageBycustomer(Integer id, Page page, Reservation reservation) {
        int count = reservationDao.pageCount(reservation);
        Object data = reservationDao.pageBycustomer(id, page, reservation);
        page.setCount(count);
        page.setData(data);
    }
}
